/*
 * spi_io.h
 *
 * Created: 8/29/2013 12:10:45 PM
 *  Author: Ken Arok
 */ 


#ifndef SPI_IO_H_
#define SPI_IO_H_

#include "config_peripherals.h"

#if SPI_PERIPHERAL_ACTIVE

#include "io.h"


/** \brief SPI Initialization.
 */
void spi_io_init(void);

/** \brief SPI I/O Control.
 *
 * \param io_desc		Pointer to I/O port descriptor.
 * \param reqCode		Request Code.
 * \param pValue		Pointer to the value.
 *
 * \return	status		pdPASS = Success, pdFAIL = failed.
 *
 */
portBASE_TYPE spi_io_ctrl(io_descriptor_t io_desc, io_request_code_t reqCode, void *pValue);

/** \brief SPI Open Peripheral.
 *
 * \param path_name		SPI port.
 * \param flag			Flag of opening.
 * 
 * \return Pointer to I/O port descriptor.
 *
 */
io_descriptor_t spi_io_open(IO_path  path_name, const uint8_t flag);

/** \brief SPI Close Peripheral.
 *
 * \param io_desc		Pointer to I/O port descriptor.
 * \param flag			Flag of closing.
 * 
 * \return	status		pdPASS = Success, pdFAIL = failed.
 *
 */
portBASE_TYPE spi_io_close(io_descriptor_t io_desc, const uint8_t flag);

/** \brief SPI Write Data to Peripheral.
 *
 * \param io_desc		Pointer to I/O port descriptor.
 * \param pBuff			Pointer to the buffer of data to write.
 * \param size			Size of data to write.
 * \param flag			Flag of writing operation.
 *
 * \return	status		pdPASS = Success, pdFAIL = failed.
 *
 */
portBASE_TYPE spi_io_write(io_descriptor_t io_desc, const void *pBuf, uint32_t size, io_rw_flag_t flag);

/** \brief SPI Read Data from Peripheral.
 *
 * \param io_desc		Pointer to I/O port descriptor.
 * \param pBuff			Pointer to the buffer where data will be copied.
 * \param size			Size of data to read.
 * \param flag			Flag of writing operation.
 *
 * \return	status		pdPASS = Success, pdFAIL = failed.
 *
 */
portBASE_TYPE spi_io_read(io_descriptor_t io_desc, void *pBuf, uint32_t size, io_rw_flag_t flag);

#else /* SPI_PERIPHERAL_ACTIVE */

#define spi_io_init()
#define spi_io_ctrl(a, b, c)		pdFAIL
#define spi_io_open(a, b)			NULL
#define spi_io_close(a)				pdFAIL
#define spi_io_write(a, b, c, d)	pdFAIL
#define spi_io_read(a, b, c, d)		pdFAIL

#endif /* SPI_PERIPHERAL_ACTIVE */

#endif /* SPI_IO_H_ */
